<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="库房">
              <a-select  v-model="queryParam.storehouse"    placeholder='请选择冷库'>
                <a-select-option v-for='d in hoseList' :key='d.id' :value='d.code'>{{ d.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='成本中心'>
              <j-dict-select-tag  v-model='queryParam.cost' :triggerChange="true" dictCode="ch_cost"   placeholder="请选择成本中心">
              </j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">

              <a-range-picker :style="{width: '100%'}"  format="YYYY-MM-DD"
                              :placeholder="['开始时间', '结束时间']"
                              v-model='rangepikerDate'
                              @change="onBirthdayChange" />

          </a-col>


          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <a-button type="primary" icon="download" @click="handleExportXls('采后物资成本')">导出</a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <flowerMaterialBook-modal ref="modalForm" @ok="modalFormOk"></flowerMaterialBook-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FlowerMaterialBookModal from './modules/FlowerMaterialBookModal'
import JDate from '@/components/jeecg/JDate.vue'
import moment from 'moment'


export default {
  name: "FlowerMaterialBookList",
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    JDate,
    FlowerMaterialBookModal,

  },
  data () {
    return {
      description: '成本中心',
      hoseList: [], //冷库
      queryParam: {},
      rangepikerDate: [],
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:40,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'库房',
          align:"center",
          dataIndex: 'storehouse_dictText'
        },{
          title:'成本中心',
          align:"center",
          dataIndex: 'cost_dictText'
        },{
          title:'日期',
          align:"center",
          dataIndex: 'outTime'
        },
         {
          title:'成本（元）',
          align:"center",
          dataIndex: 'totalPrice'
        },

      ],
      url: {
        list: "/flowermater/flowerMaterialBook/queryMaterCost",
        exportXlsUrl: "/flowermater/flowerMaterialBook/exportXls2",
      },
      dictOptions:{},
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  created() {
    let now = new Date()
    let monthNum = moment().month()
    this.queryParam.sDate =moment(now).month(monthNum).date(1).startOf("month").format("YYYY-MM-DD")
    this.queryParam.eDate = moment(now).month(monthNum).date(1).endOf("month").format("YYYY-MM-DD")
    this.rangepikerDate=[this.queryParam.sDate,  this.queryParam.eDate ]
    this.hoseList =  JSON.parse( localStorage.getItem("ch_storehouse")?localStorage.getItem("ch_storehouse"):"[]")
  },
  methods: {
    moment,
    initDictConfig(){
    },
    onBirthdayChange(date, dateString){
      this.queryParam.sDate = dateString[0]
      this.queryParam.eDate = dateString[1]
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>